<template>
  <div>
    <el-dialog :title="title" :visible.sync="visible" width="600px" append-to-body custom-class="import-dialog">
      <el-timeline v-loading="loading">
        <el-timeline-item
          v-for="(activity, index) in list"
          :key="index"
          :timestamp="activity.createTime"
        >
          <div class="sign-progress">
            <div class="sign-progress-item">
              {{ activity.signer }}
            </div>
            <div>{{ signProgressText(activity.signProgress) }}</div>
          </div>
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import { debounce } from '@/utils'
import { signProgressList } from '@/api/contract/lessee'

export default {
  name: 'sign-progress',
  props: {
    title: {
      type: String,
      default: '补充条款'
    },
    value: {
      type: Boolean,
      default: false
    },
    data: {
      // type: Array,
      default: {}
    }
  },
  data() {
    return {
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractId: '',//合同id
        contractType: '',//合同类型:1,业主合同;2.租客合同
        signer: '',//签约人
        signProgress: ''//签署进度:1.未签署;2.已签署
      },
      list: [],
      total: 0,
      signProgress: [{label: '未签署', value: 1}, {label: '已签署', value: 2}, {label: '已填写', value: 3} ]
    }
  },
  computed: {
    visible: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)   // 此处监测visible目的为关闭弹窗时，重新更换value值，注意emit的事件一定要为input。
      }
    },
    signProgressText() {
      return (value) => {
        let obj = this.signProgress.find(item => item.value == value)
        return obj ? obj.label : ''
      }
    }
  },
  watch: {
    value: {
      handler(newVal, oldVal) {
        if (newVal) {
          this.init()
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    init() {
      this.reset()
      this.getList()
    },

    reset() {
      this.list = []
      this.total = 0
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        contractId: this.data.lesseeContractId,//合同id
        contractType: '',//合同类型:1,业主合同;2.租客合同
        signer: '',//签约人
        signProgress: ''//签署进度:1.未签署;2.已签署
      }
    },
    // 获取列表
    getList() {
      this.loading = true
      signProgressList(this.queryParams).then(res => {
        this.list = res.data
        this.loading = false
      }).catch(err => {
        console.log(err)
        this.list = []
        this.loading = false
      })
    },
    // 提交
    submit: debounce(function() {
      this.$emit('update:data', this.form.supplementaryTerms)
      this.close()
    }, 500, true),
    close() {
      console.log('close')
      this.visible = false
    }
  }
}
</script>


<style scoped lang="scss">
.sign-progress{
  width: 80%;
  display: flex;
  justify-content: space-between;

}
</style>
